#!/usr/bin/python

import time


def get_time_stamp():
    ct = time.time()
    local_time = time.localtime(ct)
    data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time)
    data_secs = int(ct * 1000 % 1000)
    time_stamp = "%s.%03d" % (data_head, data_secs)
    return time_stamp


def get_interval_stamp(base):
    t = time.time() - base
    return int(t * 1000) / 1000.0


def print_interval(interval, show_milliseconds=False):
    t = interval
    hour = 0
    minute = 0
    millisecond = int((t * 1000) % 1000)
    second = int(t % 60)
    if t > 59:
        t = t / 60
        minute = int(t % 60)
        if t > 59:
            hour = int(t / 60)
    return "%02d:%02d:%02d.%03d" % (hour, minute, second, millisecond) if show_milliseconds else "%02d:%02d:%02d" % (hour, minute, second)
